# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=mailutils
pkgver=3.16
pkgrel=1
pkgdesc="MUA command line tool (mailx)"
arch=(loong64 x86_64)
url="https://www.gnu.org/software/mailutils/"
license=('GPL')
depends=('libldap' 'pam' 'gnutls' 'gsasl')
makedepends=('emacs')
options=(!emptydirs)
validpgpkeys=('325F650C4C2B6AD58807327A3602B07F55D0C732')
source=(https://ftp.gnu.org/gnu/mailutils/mailutils-$pkgver.tar.bz2{,.sig}
        fix-build-mb-len-max.patch)
sha512sums=('57c62486e4be2d974639c0b3ad1840880e188fa6618bcd256233b49a4fde36aa6c9ac7e0368c1c38e16799267944ea84913d0afd6f2c3131326663fd91cdcf91'
            'SKIP'
            '48248bfae1cc3b80c3decfcb99f803b65fd0d068f6c09625eb5e3763b3184090d7bd97fa3bc916b3e2e8c737b2bd501aa25482a96aceb555c08307b54c2a24a8')

prepare() {
  cd "$srcdir/mailutils-$pkgver"
  # Include limits.h in frm/frm.h so it doesn't misdefine MB_LEN_MAX to 4
  # (patch from github.com/NixOS/nixpkgs)
  patch -Np1 -i ../fix-build-mb-len-max.patch
}

build() {
  cd "$srcdir/mailutils-$pkgver"
  ./configure \
	--prefix=/usr \
	--sbindir=/usr/bin \
	--libexecdir=/usr/lib/$pkgname \
	--sysconfdir=/etc \
	--with-gdbm \
	--with-gnutls \
	--disable-python \
	--without-guile
  make CFLAGS="$CFLAGS -O2" || make CFLAGS="$CFLAGS -O2" LDFLAGS="-L`pwd`/lib -lmutcpwrap -ltinfo"
}

package() {
  cd "$srcdir/mailutils-$pkgver"
  make -j1 DESTDIR="$pkgdir" install
  rm -f "$pkgdir"/usr/share/info/dir
  mv "$pkgdir"/usr/bin/mail "$pkgdir"/usr/bin/gnu-mail
  mv "$pkgdir"/usr/share/man/man1/mail.1 "$pkgdir"/usr/share/man/man1/gnu-mail.1
  chown -R root:root "$pkgdir"
}
